﻿using System.ComponentModel;
using System.Web.Script.Services;
using System.Web.Services;
using Module;

namespace HospitalManager.Webservice
{
    /// <summary>
    ///     Summary description for wsSelectAll
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [ScriptService]
    public class wsSelectAll : WebService
    {
        private readonly SelectAllClass _selectAllClass = new SelectAllClass();

        [WebMethod(EnableSession = true)]
        public string CheckSession()
        {
            var sessionUserName = Session["username"] == null ? "" : Session["username"].ToString().Trim();
            return (sessionUserName + ";" + (Session.Timeout * 60 * 1000));// Timeout tính ra milliseconds
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllLoaiKhachHang()
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllLoaiKhachHang());
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllLoaiVatTu()
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllLoaiVatTu());
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllNhomVatTu(string maloaivattu)
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllNhomVatTu(maloaivattu));
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllVatTu(string manhomvatttu)
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllVatTu(manhomvatttu));
        }

        [WebMethod(EnableSession = true)]
        public string SelectDonViById(string madonvi)
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectDonViById(madonvi));
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllThue()
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllThue());
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllKho()
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllKho());
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllNhaCungCap()
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllNhaCungCap());
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllNguonGocXuatXu()
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllNguonGocXuatXu());
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllKhoa()
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllKhoa());
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllDoiTuongBaoHiem()
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllDoiTuongBaoHiem());
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllTaiKhoan()
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllTaiKhoan());
        }

        [WebMethod(EnableSession = true)]
        public string SelectAllChucVu()
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectAllChucVu());
        }

        [WebMethod(EnableSession = true)]
        public string SelectVatTuById(string mavattu)
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectVatTuById(mavattu));
        }

        [WebMethod(EnableSession = true)]
        public string SelectKhachHangByMaLoaiKhachHang(string maloaikhachhang)
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectKhachHangByMaLoaiKhachHang(maloaikhachhang));
        }

        [WebMethod(EnableSession = true)]
        public string SelectTaiKhoanById(string id)
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectTaiKhoanById(id));
        }

        [WebMethod(EnableSession = true)]
        public string SelectKhoByKhoa(string makhoa)
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectKhoByKhoa(makhoa));
        }

        [WebMethod(EnableSession = true)]
        public string SelectPhongBanByKhoa(string makhoa)
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectPhongBanByKhoa(makhoa));
        }

        [WebMethod(EnableSession = true)]
        public string SelectVatTuByMaKho(string makho)
        {
            return JsonMethods.ToJsonString(_selectAllClass.SelectVatTuByMaKho(makho));
        }

        [WebMethod(EnableSession = true)]
        public string CheckTon_Ma_Lo_PhieuNhap(string mavattu, string losanxuat, string maphieunhap, string makho)
        {
            return
                JsonMethods.ToJsonString(_selectAllClass.CheckTon_Ma_Lo_PhieuNhap(mavattu, losanxuat, maphieunhap, makho));
        }

        [WebMethod(EnableSession = true)]
        public string CheckTon_Ma_Lo_PhieuNhap_NotHSD(string mavattu, string losanxuat, string maphieunhap, string makho)
        {
            return
                JsonMethods.ToJsonString(_selectAllClass.CheckTon_Ma_Lo_PhieuNhap_NotHSD(mavattu, losanxuat, maphieunhap,
                    makho));
        }

        [WebMethod(EnableSession = true)]
        public string CheckTon_MaKho_MaVatTu(string makho, string mavattu)
        {
            return JsonMethods.ToJsonString(_selectAllClass.CheckTon_MaKho_MaVatTu(makho, mavattu));
        }

        [WebMethod(EnableSession = true)]
        public string CheckTonThucTe_MaKho_MaVatTu(string makho, string mavattu)
        {
            return JsonMethods.ToJsonString(_selectAllClass.CheckTonThucTe_MaKho_MaVatTu(makho, mavattu));
        }

        [WebMethod(EnableSession = true)]
        public string TrangThaiTaiKhoan(string taikhoan)
        {
            bool status;
            _selectAllClass.TrangThaiTaiKhoan(taikhoan, out status);
            return status
                ? "Tài khoản đang sử dụng hoặc chức vụ cũ còn tồn đọng công việc, vui lòng đăng xuất hoặc xử lý hết công việc trước đó"
                : "";
        }
    }
}